//
//  HMEmoticonButton.swift
//  WeiBo
//
//  Created by apple on 16/7/2.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class HMEmoticonButton: UIButton {


    var emoticon: HMEmoticon?{
    
        didSet{
            
            // 2. 赋值 -- 测试
            //                button.setTitle(emoticon.chs, forState: UIControlState.Normal)
            // 如何区分 图片表情以及 emoji? 我们可以通过对象里 emoji 与 png 为空的情况去区分
            if let png = emoticon?.png,path = emoticon?.path {
                // 图片表情
                // /Users/apple/Library/Developer/CoreSimulator/Devices/C4B16C32-00BA-46B4-880F-8A0ECCA1DE13/data/Containers/Bundle/Application/9886DC31-6F15-4FA0-B191-C728BF124C0A/WeiBo.app/Emoticons.bundle/com.sina.default\")/Optional(\"d_zuiyou.png\")
                let imageName = "\(path)/\(png)"
                self.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
                
            } else {
                // 一定要注意cell的重用
                self.setImage(nil, forState: UIControlState.Normal)
                
            }
            
            
            if let emoji = emoticon?.emoji {
                
                // emoji
                self.setTitle(emoji, forState: UIControlState.Normal)
            } else {
                
                // 还是由于cell的重用
                self.setTitle(nil, forState: UIControlState.Normal)
            }

            
        }
        
    }

}
